<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 父类构造函数
        function Father(name, age) {
            this.name = name;
            this.age = age;
        };
        // 父类中的方法
        Father.prototype.makeMoney = function() {
            console.log('挣钱');
        };
        // 子类构造函数
        function Son(name, age, height) {
            // 构造函数继承
            Father.call(this, name, age);
            this.height = height;
        };

        // Son.prototype = Father.prototype;
        // 使用Object.create()方法实现继承
        Son.prototype = Object.create(Father.prototype, {
            constructor: {
                value: Son,
                configurable: true,
                enumerable: true,
                writable: true
            },
            spend: {
                value: function() {
                    console.log('花钱');
                },
                configurable: true,
                enumerable: true,
                writable: true
            }
        });

        // // 添加子类的方法
        // Son.prototype.spend = function() {
        //     console.log('花钱');
        // };

        var father = new Father('小头爸爸', 30);
        var son = new Son('大头儿子', 5, 100);
        console.log(father);
        console.log(son);
        son.makeMoney();
        son.spend();
    </script>
</body>

</html>